#pragma comment(linker, "/STACK:10000000")
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>
#include <cstdio>
#include <cassert>
#include <string>
#include <cstring>
#define ldb long double
#define LL long long
#define fi first
#define se second
#define fill(a, c) memset(a, c, sizeof(a))
#define sqr(a) ((a) * (a))
#define nextLine() {int c = 0; while((c = getchar()) != 10 && c != EOF);}
#define getBit(mask, k) (((mask) / pw[k]) % pw[1])
#define setBit(mask, k, l) (((mask) / pw[k + 1] * pw[1] + (l)) * pw[k] + ((mask) % pw[k]))
#define debug(a) cerr << #a << " = " << a << " ";
#define debugl(a) cerr << #a << " = " << a << "\n";
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define ff first
#define ss second 
const ldb LDINF = 9128739847123.00;
const ldb eps = 1e-9;
const int inf = 1 << 28;
const ldb pi = fabsl(atan2l(0.0, -1.0));
using namespace std;


int nxt[5001 * 5001 + 1], end[5001 * 5001 + 1], fst[5001 + 1], edgs;
char a[5001][5002];
int n;

void load()
{
	cin >> n;
	memset(fst, -1, sizeof fst);
	nextLine();
	for (int i = 0; i < n; i++)
	{
		gets(a[i]);
		for (int j = 0; j < n; j++)
		{
			a[i][j] -= '0';
			if (a[i][j])
			{
				nxt[edgs] = fst[i];
				fst[i] = edgs;
				end[edgs] = j;
				edgs++;
			}
		}
	}

}

int was[5001];
vector <int> path;

bool find_cycle(int i)
{
	was[i] = 1;
	path.pb(i);
	for (int u = fst[i]; u != -1; u = nxt[u])
	{
		if (was[end[u]] == 2) continue;
		if (was[end[u]] == 1)
		{
			path.erase(path.begin(), find(path.begin(), path.end(), end[u]));
			return true;
		}
		if (find_cycle(end[u])) return true;
	}
	was[i] = 2;
	path.pop_back();
	return false;
}

int nx[5001];

void solve()
{
	for (int i = 0; i < n; i++)
	{
		if (was[i]) continue;
		path.resize(0);
		if (find_cycle(i))
		{
			for (int i = 0; i < path.size(); i++)
			{
				nx[path[i]] = path[(i + 1) % path.size()];
			}
			int f = path[0];
			int sz = path.size();
			while (sz > 3)
			{
				if (a[nx[nx[f]]][f] == 1)
				{
					printf("%d %d %d", f + 1, nx[f] + 1, nx[nx[f]] + 1);
					return;
			  	}
			  	nx[f] = nx[nx[f]];
			  	sz--;
			}
			if (sz == 3)
			{
				printf("%d %d %d", f + 1, nx[f] + 1, nx[nx[f]] + 1);
				return;
			}
		}
	}
	printf("-1");
}

#define file "c"
int main()
{
	#ifndef ONLINE_JUDGE
		freopen(file".in", "rt", stdin);
		freopen(file".out", "wt", stdout);
	#endif
	load();
	solve();
	return 0;
}
